<?php session_start(); ?>
<?php
include('../ketnoi.php');
if (!$_SESSION['user']) header("location: index.php"); // nếu biến session['banguyen'] chưa có thì trở về trang đăng nhập, copy dòng này vào trang nào muốn bảo vệ bằng mật khẩu
?>
<style type="text/css">
<!--
.error, .notice, .success {padding:.8em;margin:auto; margin-bottom:.5em;border:2px solid #AAF;width:570px;text-align: center}
.error {background: #ECECFF;color: red;border-color:#AAF;}
-->
</style>
<style type="text/css">
.xem {
FONT-SIZE: 10pt; 
	COLOR: #000000;
	BORDER:0px;
	background-color:#FFFFFF;
}
</style>
<script type="text/javascript" src="scripts/joomla.js"></script>
<div class="m">
 <?php 
    $shop=$dulieu;
	if($_GET['action']=='view' && $_GET['option']=='com_banner')
	{

		$sql1 = "SELECT * FROM `".$shop."`.`hinhanh` order by vitri asc";
		$ketqua1 = mysql_query($sql1) or die ('khong tim thay du lieu');	
		$tong1=mysql_num_rows($ketqua1);		
?>

<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="index.php"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>

	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" href="?option=com_banner&action=insert_intro"><img src="images/toolbar/icon-32-new.png" alt="New"><br><span>New</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/install.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Quản lý hình ảnh giới thiệu</h2></div><br /><br />
<form name="adminForm" action="" method="post">
					
					<input name="option" value="com_banner" type="hidden">
					<input name="boxchecked" type="hidden">
					<input name="task" value="" type="hidden">
					<input name="func" value="" type="hidden">


<table class="adminlist" width="100%">
<tbody><tr><th width="2%" class="title"> # </th>
<th width="2%" class="title"><input name="toggle" value="" onclick="checkAll(<?php echo $tong1; ?>)" type="checkbox"></th>
<th class="title" width="53%"> Hình ảnh banner</th>
<th class="title" width="30%"> Vị trí </th>
<th class="title" width="10%"> Hiển thị</th>
<th class="title" width="3%"> Xóa</th>
</tr>
 <?php 
	$stt=0;
	$t=0;
   while($dongDL1 = mysql_fetch_array($ketqua1))
	  { 
  ?>
  
<tr class="row<?php echo $t ?>">
<td><?php echo $stt+1 ?></td>
<td align="center"><input id="cb<?php echo $stt ?>" name="product_id[<?php echo $dongDL1['vitri']?>]" value="<?php echo $dongDL1['vitri']?>" onclick="isChecked(this.checked);" type="checkbox"></td>
<td align="center"><img src="../upload/<?php echo $dongDL1['hinh']?>" width="333" height="77"></td>
<td class="order" align="center">
<?php if( $dongDL1['vitri']!=$tong1){ ?>
	<a href="?option=com_banner&action=update_dx&amp;idtt=<?php echo $dongDL1['vitri'] ?>" title="Đi Xuống"><img src="images/downarrow.png" alt="Đi Xuống" width="16" border="0" height="16"></a> <?php }else{ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' ;} ?>
	<input disabled="disabled" name="order[<?php echo $dongDL1['vitri']?>]" size="4" value="<?php echo $dongDL1['vitri'] ?>" class="text_area" style="text-align: center;" type="text">
<?php if( $dongDL1['vitri']!=1){ ?>
	<a href="?option=com_banner&action=update_dl&amp;idtt=<?php echo $dongDL1['vitri'] ?>" title="Đi Lên"><img src="images/uparrow.png" alt="Đi Lên" width="16" border="0" height="16"></a>  <?php }else{ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' ;} ?>
</td>
<td align="center">
<a href="?option=com_banner&action=update_intro&amp;id=<?php echo $dongDL1['vitri'] ?>"><?php if($dongDL1['hienthi']==0){echo "<img src='images/publish_x.png'>"; }else{ echo "<img src='images/tick.png'>";}?></a> 
</td>
<td align="center"><a class="toolbar" href="?option=com_banner&action=delete_intro&amp;id=<?php echo $dongDL1['vitri'] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa?');"><img src="images/delete_f2.png" width="20" height="20"alt="Delete"  align="middle" border="0"></a></td>
</tr>
	 <?php
	 $stt=$stt+1;
	 if($t==0)$t=1;
	 else $t=0;
	  }//ket thuc ham while in du lieu
	  ?>
      
<tr>
<td colspan="9"><table width="100%"><tr>
<td width="45%" align="right" nowrap="nowrap">Display #</td><td width="10%">
<select class="inputbox" name="limit" size="1" disabled="disabled">
<option><?php echo $tong1; ?></option>
</select>
</td><td width="45%" align="left" nowrap="nowrap"><?php if($tong1 >0){?>Results 1 - 
<?php echo $tong1;?> of <?php echo $tong1; }?></td></tr>
</table></td>
</tbody></table>
</form>


<?php
}//ket thuc view



if($_GET['action']=='insert_intro' && $_GET['option']=='com_banner')
{
if(isset($_FILES["ts1"]["name"])){
	$error="";
	if($_FILES["ts1"]["name"]==""){
	  $error="Vui lòng nhập đầy đủ các field.";
    }else{
        move_uploaded_file($_FILES["ts1"]["tmp_name"],"../update/".$_FILES["ts1"]["name"]);
		$sql_t = "SELECT * FROM `".$shop."`.`hinhanh` ";
		$ketqua_t = mysql_query($sql_t) or die ('khong tim thay du lieu');
		$tong=mysql_num_rows($ketqua_t);
		$tong=$tong+1;
        $sql = "INSERT INTO `".$shop."`.`hinhanh` (`hinh`,`hienthi`,`vitri`) VALUES ('".$_FILES["ts1"]["name"]."',1,'".$tong."');";
		$insert = mysql_query($sql);
        echo"<script language=javascript>window.location='index.php?option=com_banner&action=view';</script>";
	}
}
	?>
	<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="?option=com_banner&action=view"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onclick="adminForm2.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/impressions.png)  no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Hình ảnh giới thiệu: [ Thêm mới ]</h2>
</div><br /><br />
<?php
	if($error!=""){
	?>
	 <div class="error" align="center"><img src='../images/cancel_f2.png' width='10px' height='10px'/> <?php echo $error ?></div>
  <?php
  }
?>
	<form name="adminForm2" action="" method="post" enctype="multipart/form-data">

<div style="height: auto; width: 1012px;" id="ext-gen37">
<div class="tab-page" id="info-page">
<table class="adminform">
	<tbody><tr> 
   		<td width="689" valign="top">
			<table width="100%" border="0">
      			<tbody><tr> 
       				<td colspan="2" align="left"><h3>Hình ảnh</h3></td>
    			</tr>
    			<tr class="row1"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">Hình ảnh:</div>      				</td>
      				<td width="71%" style="padding-left:15px"> 
       				  <input name="ts1" type="file" class="inputbox" /> 	</td>
    			</tr>
				
    			 <tr class="row0"> 
    					    
		      		<td valign="top" width="29%">&nbsp;</td>
		      		<td width="71%">&nbsp;</td>		    
	    			</tr>
	  			  </tbody></table>
 		</td>
  	</tr>
</tbody></table>

</div>
</div>
</form>
<?php
}// ket thuc kiem tra action insert



if($_GET['action']=='update_intro' && $_GET['option']=='com_banner')
 {
         $query1 = "select * from `".$shop."`.`hinhanh` WHERE `vitri` = '".$_GET['id']."'";
		 $kq1 = mysql_query($query1);
		 $dongDL1 = mysql_fetch_array($kq1);
   if($dongDL1['hienthi']==0){
		$sql = "UPDATE `".$shop."`.`hinhanh` SET  `hienthi` = 1  WHERE `vitri` = '".$_GET['id']."'";
		$update = mysql_query($sql) or die($sql);
        echo"<script language=javascript>window.location='index.php?option=com_banner&action=view';</script>";
   }
    if($dongDL1['hienthi']==1){
        $sql = "UPDATE `".$shop."`.`hinhanh` SET  `hienthi` = 0  WHERE `vitri` = '".$_GET['id']."'";
		$update = mysql_query($sql) or die($sql);
        echo"<script language=javascript>window.location='index.php?option=com_banner&action=view';</script>";
   }
		
 } 
 
 
  
  if($_GET['action']=='update_dx' && $_GET['option']=='com_banner')
{
        $_SESSION['idtt']=$_GET['idtt'];
        $sql ="SELECT * from `".$shop."`.`hinhanh` WHERE `vitri` = '".$_GET['idtt']."'";
		$ketqua = mysql_query($sql);
		$dulieu = mysql_fetch_array($ketqua);		
        $xuong=$dulieu['vitri']+1;
		
		$sql1 ="SELECT * from `".$shop."`.`hinhanh` WHERE  vitri='".$xuong."'";
		$ketqua1 = mysql_query($sql1);
		$dulieu1 = mysql_fetch_array($ketqua1);
		
		$sql2 = "UPDATE `".$shop."`.`hinhanh` SET  `vitri` = '".$xuong."'  WHERE `vitri` = '".$_SESSION['idtt']."'";
        $update2 = mysql_query($sql2);
		
		$sql3 = "UPDATE `".$shop."`.`hinhanh` SET  `vitri` = '".$dulieu['vitri']."' WHERE `hinh` = '".$dulieu1['hinh']."'";
		$update3 = mysql_query($sql3);
		
		 echo"<script language=javascript>window.location='index.php?option=com_banner&action=view';</script>";
 
}

if($_GET['action']=='update_dl' && $_GET['option']=='com_banner')
{
        $_SESSION['idtt']=$_GET['idtt'];
        $sql ="SELECT * from `".$shop."`.`hinhanh` WHERE `vitri` = '".$_GET['idtt']."'";
		$ketqua = mysql_query($sql);
		$dulieu = mysql_fetch_array($ketqua);		
        $xuong=$dulieu['vitri']-1;
		
		$sql1 ="SELECT * from `".$shop."`.`hinhanh` WHERE vitri ='".$xuong."'";
		$ketqua1 = mysql_query($sql1);
		$dulieu1 = mysql_fetch_array($ketqua1);
  
		
		$sql2 = "UPDATE `".$shop."`.`hinhanh` SET  `vitri` = '".$xuong."'  WHERE `vitri` = '".$_SESSION['idtt']."'";
		$update2 = mysql_query($sql2);
		
        $sql3 = "UPDATE `".$shop."`.`hinhanh` SET  `vitri` = '".$dulieu['vitri']."' WHERE `hinh` = '".$dulieu1['hinh']."'";
		$update3 = mysql_query($sql3);
	   echo"<script language=javascript>window.location='index.php?option=com_banner&action=view';</script>";
 
} 
?>


</div>
